<template>
  <div>
    <div class="wrap">
      <div class="show-title">
        <span>网关挂载设备列表</span>
      </div>
      <!-- 搜索 -->
      <div class="searchBox">
        <el-input
          prefix-icon="el-icon-search"
          v-model="searchTableInfo"
          placeholder="请输入搜索内容"
          style="width:30%"
          clearable
        ></el-input>
      </div>
      <!-- 列表 -->
      <el-table
        ref="table"
        :data="tableData.slice((currpage - 1) * pagesize, currpage * pagesize)"
        border
        style="width: 100%"
        stripe
        @selection-change="handleSelectionChange"
        @sort-change="changeSort"
        :row-key="getRowKeys"
      >
        <el-table-column
          type="selection"
          width="40"
          align="center"
          :reserve-selection="true"
        ></el-table-column>
        <el-table-column
          prop="sn"
          label="序列号"
          min-width="320"
          align="center"
          sortable="true"
        >
          <template scope="scope">
            <div @click="goYdtDeviceList(scope.row)">
              {{ decodeURI(scope.row.sn) }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          prop="name"
          label="名称"
          min-width="200"
          align="center"
        >
          <template slot-scope="scope">{{
            decodeURI(scope.row.name)
          }}</template>
        </el-table-column>
        <el-table-column
          prop="chns"
          label="通道数"
          min-width="60"
          align="center"
        >
          <template slot-scope="scope">{{
            decodeURI(scope.row.chns)
          }}</template>
        </el-table-column>
        <el-table-column
          prop="address"
          label="出口IP地址"
          min-width="120"
          align="center"
        >
          <template slot-scope="scope">{{
            decodeURI(scope.row.address)
          }}</template>
        </el-table-column>
        <el-table-column
          prop="created_time"
          label="注册时间"
          min-width="120"
          align="center"
          sortable
        >
          <template slot-scope="scope">{{
            decodeURI(scope.row.created_time)
          }}</template>
        </el-table-column>
      </el-table>
      <!--分页-->
      <el-pagination
        right
        background
        layout="total,prev, pager, next, sizes,jumper"
        :page-sizes="[5, 10, 15, 25]"
        :page-size="pagesize"
        :total="tableData.length"
        @current-change="handleCurrentChange"
        @size-change="handleSizeChange"
      ></el-pagination>

      <!--删除全部设备  -->
      <!-- <div class="batch-btn-con">
      <el-button class="batchDelect" type="warning" plain @click="batchDelete">批量冻结API</el-button>
      <el-button class="batchDelect" type="warning" plain @click="batchDelete">批量激活API</el-button>
      <el-link
        class="tips"
        :underline="false"
        type="info"
        icon="el-icon-warning-outline"
      >冻结API：冻结API后，所有开发者及应用请求将会被拒绝。</el-link>
      <el-link
        class="tips"
        :underline="false"
        type="info"
        icon="el-icon-warning-outline"
      >激活API：激活API后，可继续提高服务。</el-link>
      </div>-->
    </div>
  </div>
</template>

<script>
import { getData, postData } from "@/request/http";
export default {
  name: "",
  props: {},
  data() {
    return {
      currpage: 1, //分页
      pagesize: 5, //分页
      searchTableInfo: "", //搜索条件
      getSearchInfo: [], //搜索后，过滤后的tableData数据
      tableChecked: [], // 多选
      batchDelectId: [], //批量删除id
      checkAll: false, // 是否全选状态
      ydt_sn: "",
    };
  },
  computed: {
    // 根据计算属性模糊搜索
    tableData() {
      const searchTableInfo = this.searchTableInfo;
      //console.log(searchTableInfo);
      if (searchTableInfo) {
        return this.getSearchInfo.filter((item) => {
          return Object.keys(item).some((key) => {
            return (
              String(item[key])
                .toLowerCase()
                .indexOf(searchTableInfo) > -1
            );
          });
        });
      }
      return this.getSearchInfo;
    },
    //刷新table
    submitData() {
      return this.$store.state.submitData;
    },
  },
  watch: {
    //刷新table
    submitData(newVal, oldVal) {
      if (newVal != oldVal) {
        //this.getList();
        this.currpage = 1;
      }
    },
  },
  created() {},
  mounted() {
    this.ydt_sn = this.$route.query.sn;
    this.getList();
  },
  methods: {
    // 获取row的key值
    getRowKeys(row) {
      return row.org_id;
    },
    //点击 第几页
    handleCurrentChange(cpage) {
      this.currpage = cpage;
    },
    //每页有几条
    handleSizeChange(psize) {
      this.pagesize = psize;
    },
    //操作多选
    handleSelectionChange(val) {
      var that = this;
      this.batchDelectId = [];
      that.tableChecked = val;
      console.log(that.tableChecked);
      if (val.length > 0) {
        for (let i = 0; i < val.length; i++) {
          this.batchDelectId.push(val[i]["role_id"]);
        }
      }
    },
    //排序
    changeSort(val) {
     // console.log(val);
    },
    //获取初始列表数据
    getList() {
      postData("/adminweb/gateway/device/list", { sn: this.ydt_sn })
        .then((res) => {
         // console.log(res);
          if (res.code == 0) {
            let devices = res.datas.devices;
            this.getSearchInfo = devices;
          } else if (res.code == -56055) {
            return;
          } else {
            this.$message.error(res.code + "，" + res.msg);
          }
        })
        .catch((res) => {
          this.$message.error(res.code + "，" + res.msg);
        });
    },

    //点击序列号，跳转到,盒子挂载设备列表
    goYdtDeviceList(val) {
      // var serialNum = val.serialNum;
      // console.log(serialNum);
      // this.$router.push({
      //   path: "/ydtBox/ydtDeviceList",
      //   params: { serialNum: serialNum }
      // });
    },
  },
};
</script>
<style scoped>
.wrap {
  background-color: #fff;
  padding: 15px;
  overflow: hidden;
}
.searchBox {
  margin-bottom: 20px;
}
.wrap >>> .el-pagination {
  float: right;
  margin-top: 30px;
}

.batch-btn-con {
  background: #fff;
  margin-top: 70px;
}
.wrap >>> .tips {
  margin-top: 10px;
  display: block;
  font-size: 15px;
}

/* 更改table,表头背景 */
.wrap >>> .el-table--border th,
.el-table__fixed-right-patch {
  /* background: #c0dee2; */
  background: #f0f3f4;
}
/*title*/
.show-title {
  width: 100%;
  height: 40px;
  line-height: 40px;
  position: relative;
  background: #c0dee2;
  padding-left: 15px;
  font-size: 14px;
  margin: 6px 0 20px 0;
  border-radius: 12px 12px 0 0;
  font-weight: bold;
}

.show-title::before {
  content: "";
  width: 2px;
  height: 16px;
  background: #676a6d;
  position: absolute;
  top: 12px;
  left: 27px;
}

.show-title span {
  float: left;
  color: #676a6d;
  margin-left: 25px;
}
</style>
